Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 307)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.53129 11.56980 11.60797 11.64580 11.68331 11.72049 11.75734 11.79389
## [9] 11.83012 11.86605 11.90168 11.93701 11.97205 12.00681 12.04126 12.07542
## [17] 12.10926 12.14278 12.17598 12.20886 12.24140 12.27360 12.30564 12.33763
## [25] 12.36952 12.40124 12.43273 12.46393 12.49478 12.52521 12.55516 12.58457
## [33] 12.61337 12.64150 12.66963 12.69818 12.72676 12.75500 12.78251 12.80890
## [41] 12.83378 12.85916 12.88673 12.91558 12.94480 12.97350 13.00076 13.02570
## [49] 13.04739 13.06495 13.08129 13.09913 13.11726 13.13448 13.14958 13.16138
## [57] 13.16865 13.17204 13.17309 13.17189 13.16854 13.16315 13.15581 13.14662
## [65] 13.13569 13.12312 13.10901 13.09346 13.07658 13.05845 13.03432 13.00175
## [73] 12.96431 12.92559 12.88917 12.85864 12.82888 12.79346 12.75401 12.71213
## [81] 12.66945 12.62759 12.58814 12.55274 12.52300 12.49624 12.46894 12.44137
## [89] 12.41385 12.38666 12.36012 12.33451 12.31014 12.28730 12.26630 12.24743
## [97] 12.23098 12.21772 12.20775 12.20039 12.19497 12.19082 12.18726 12.18362
## [105] 12.17922 12.17339 12.16744 12.16294 12.15960 12.15712 12.15521 12.15359
## [113] 12.15195 12.15056 12.14982 12.14972 12.15021 12.15127 12.15286 12.15495
## [121] 12.15751 12.16050 12.16390 12.16767 12.17178 12.17717 12.18437 12.19270
## [129] 12.20150 12.21009 12.21781 12.22398 12.23050 12.23923 12.24948 12.26054
## [137] 12.27171 12.28228 12.29155 12.29882 12.30337 12.30462 12.30287 12.29879
## [145] 12.29304 12.28627 12.27915 12.27234 12.26650 12.26229 12.26036 12.26139
## [153] 12.26603 12.27089 12.27287 12.27310 12.27267 12.27271 12.27432 12.27862
## [161] 12.28672 12.29973 12.31793 12.34039 12.36637 12.39514 12.42596 12.45810
## [169] 12.49083 12.52341 12.55510 12.58518 12.61291 12.63755 12.66411 12.69734
## [177] 12.73611 12.77929 12.82578 12.87444 12.92416 12.97381 13.02228 13.06844
## [185] 13.11116 13.14934 13.18184 13.20755 13.22535 13.23410 13.23547 13.23238
## [193] 13.22559 13.21588 13.20401 13.19075 13.17689 13.15818 13.13077 13.09602
## [201] 13.05524 13.00980 12.96101 12.91023 12.85879 12.80803 12.75929 12.71391
## [209] 12.67322 12.63134 12.58309 12.53087 12.47709 12.42418 12.37454 12.33059
## [217] 12.28968 12.24782 12.20539 12.16280 12.12044 12.07872 12.03802 11.99874
## [225] 11.96128 11.92472 11.88812 11.85181 11.81614 11.78145 11.74809 11.71639
## [233] 11.68514 11.65318 11.62090 11.58872 11.55703 11.52624 11.49676 11.46898
## [241] 11.44330 11.42015 11.39990 11.38298 11.36799 11.35350 11.33988 11.32747
## [249] 11.31663 11.30772 11.30109 11.29710 11.29610 11.29822 11.30322 11.31087
## [257] 11.32095 11.33326 11.34756 11.36365 11.38130 11.40030 11.42043 11.44146
## [265] 11.46319 11.49152 11.52997 11.57473 11.62201 11.66799 11.70887 11.74085
## [273] 11.76884 11.79953 11.83176 11.86441 11.89633 11.92638 11.95341 11.97629
## [281] 11.99388 12.00820 12.02190 12.03475 12.04653 12.05701 12.06597 12.07318
## [289] 12.07900 12.08387 12.08772 12.09046 12.09203 12.09234 12.09132 12.08888
## [297] 12.08495 12.07944 12.07229 12.06342 12.05260 12.03977 12.02509 12.00871
## [305] 11.99079 11.97147 11.95090
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 307)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.71290 10.80584 10.89688 10.98603 11.07326 11.15856 11.24191 11.32332
## [9] 11.40275 11.48020 11.55565 11.62910 11.70052 11.76989 11.83721 11.90251
## [17] 11.96583 12.02721 12.08668 12.14429 12.20007 12.25406 12.30596 12.35552
## [25] 12.40284 12.44802 12.49115 12.53234 12.57168 12.60928 12.64523 12.67964
## [33] 12.71260 12.74421 12.77393 12.80133 12.82666 12.85019 12.87217 12.89285
## [41] 12.91250 12.92947 12.94240 12.95203 12.95907 12.96424 12.96826 12.97187
## [49] 12.97578 12.98071 12.98455 12.98531 12.98392 12.98131 12.97838 12.97608
## [57] 12.97532 12.97525 12.97444 12.97296 12.97085 12.96818 12.96501 12.96140
## [65] 12.95741 12.95309 12.94851 12.94372 12.93878 12.93376 12.92916 12.92507
## [73] 12.92089 12.91603 12.90989 12.90187 12.89298 12.88445 12.87598 12.86729
## [81] 12.85807 12.84805 12.83693 12.82442 12.81024 12.79452 12.77766 12.75981
## [89] 12.74109 12.72162 12.70153 12.68095 12.66001 12.63884 12.61756 12.59629
## [97] 12.57517 12.55382 12.53174 12.50886 12.48515 12.46054 12.43499 12.40844
## [105] 12.38083 12.35212 12.31765 12.27508 12.22782 12.17928 12.13287 12.09200
## [113] 12.06009 12.03147 11.99899 11.96386 11.92727 11.89041 11.85450 11.82071
## [121] 11.79026 11.76434 11.74414 11.73086 11.72571 11.72764 11.73410 11.74399
## [129] 11.75620 11.76965 11.78322 11.79582 11.81224 11.83666 11.86706 11.90143
## [137] 11.93777 11.97407 12.00832 12.03851 12.06263 12.08598 12.11452 12.14732
## [145] 12.18339 12.22179 12.26154 12.30168 12.34126 12.37931 12.41486 12.44696
## [153] 12.47463 12.49863 12.52064 12.54116 12.56070 12.57974 12.59877 12.61830
## [161] 12.63882 12.66083 12.68322 12.70467 12.72529 12.74519 12.76450 12.78334
## [169] 12.80181 12.82005 12.83816 12.85627 12.87449 12.89295 12.91367 12.93819
## [177] 12.96584 12.99597 13.02793 13.06104 13.09467 13.12815 13.16082 13.19203
## [185] 13.22112 13.24743 13.27031 13.28910 13.30314 13.31178 13.31686 13.32052
## [193] 13.32262 13.32298 13.32144 13.31782 13.31195 13.30338 13.29191 13.27776
## [201] 13.26118 13.24238 13.22161 13.19909 13.17506 13.14976 13.12341 13.09624
## [209] 13.06850 13.04025 13.01125 12.98125 12.94998 12.91720 12.88264 12.84606
## [217] 12.80408 12.75475 12.69994 12.64153 12.58140 12.52141 12.46345 12.40939
## [225] 12.36109 12.31105 12.25286 12.19010 12.12635 12.06521 12.01023 11.96502
## [233] 11.92665 11.88979 11.85434 11.82022 11.78733 11.75559 11.72491 11.69520
## [241] 11.66637 11.63834 11.61102 11.58431 11.55825 11.53307 11.50899 11.48623
## [249] 11.46502 11.44559 11.42815 11.41292 11.40014 11.38908 11.37895 11.36988
## [257] 11.36198 11.35537 11.35018 11.34651 11.34450 11.34425 11.34589 11.34953
## [265] 11.35531 11.36204 11.36885 11.37627 11.38481 11.39501 11.40739 11.42249
## [273] 11.44311 11.47047 11.50275 11.53812 11.57475 11.61081 11.64447 11.67390
## [281] 11.69728 11.71809 11.74064 11.76429 11.78841 11.81237 11.83554 11.85728
## [289] 11.87835 11.89986 11.92170 11.94377 11.96598 11.98821 12.01036 12.03234
## [297] 12.05404 12.07536 12.09619 12.11644 12.13571 12.15385 12.17109 12.18768
## [305] 12.20387 12.21990 12.23600
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 307)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.82100 10.88642 10.95060 11.01354 11.07518 11.13551 11.19450 11.25211
## [9] 11.30831 11.36309 11.41640 11.46823 11.51853 11.56732 11.61468 11.66065
## [17] 11.70527 11.74859 11.79067 11.83154 11.87127 11.90989 11.94666 11.98099
## [25] 12.01313 12.04334 12.07188 12.09901 12.12499 12.15007 12.17451 12.19858
## [33] 12.22252 12.24660 12.26977 12.29114 12.31117 12.33036 12.34919 12.36814
## [41] 12.38769 12.40844 12.43033 12.45286 12.47552 12.49781 12.51921 12.53923
## [49] 12.55735 12.57307 12.58820 12.60433 12.62056 12.63601 12.64980 12.66106
## [57] 12.66889 12.67369 12.67654 12.67761 12.67705 12.67502 12.67170 12.66723
## [65] 12.66179 12.65552 12.64860 12.64118 12.63343 12.62551 12.61556 12.60240
## [73] 12.58716 12.57099 12.55503 12.54041 12.52553 12.50832 12.48926 12.46881
## [81] 12.44745 12.42565 12.40388 12.38262 12.36233 12.34104 12.31690 12.29059
## [89] 12.26276 12.23408 12.20522 12.17684 12.14961 12.12419 12.10125 12.08145
## [97] 12.06546 12.05236 12.04065 12.03015 12.02065 12.01197 12.00391 11.99628
## [105] 11.98888 11.98153 11.97624 11.97430 11.97447 11.97550 11.97613 11.97512
## [113] 11.97122 11.96599 11.96174 11.95833 11.95562 11.95346 11.95172 11.95025
## [121] 11.94891 11.94756 11.94607 11.94428 11.94207 11.94025 11.93949 11.93934
## [129] 11.93940 11.93922 11.93840 11.93649 11.93259 11.92644 11.91859 11.90962
## [137] 11.90010 11.89060 11.88167 11.87390 11.86784 11.86092 11.85076 11.83821
## [145] 11.82412 11.80932 11.79468 11.78104 11.76925 11.76016 11.75462 11.75347
## [153] 11.75757 11.76502 11.77346 11.78298 11.79370 11.80573 11.81918 11.83415
## [161] 11.85076 11.86912 11.89060 11.91607 11.94488 11.97638 12.00991 12.04481
## [169] 12.08045 12.11615 12.15127 12.18516 12.21716 12.24662 12.27826 12.31653
## [177] 12.36039 12.40880 12.46071 12.51508 12.57085 12.62700 12.68247 12.73622
## [185] 12.78720 12.83437 12.87668 12.91309 12.94256 12.96404 12.97986 12.99309
## [193] 13.00374 13.01186 13.01747 13.02062 13.02133 13.01841 13.01098 12.99954
## [201] 12.98456 12.96656 12.94601 12.92342 12.89928 12.87408 12.84831 12.82247
## [209] 12.79705 12.76908 12.73620 12.69979 12.66127 12.62204 12.58349 12.54702
## [217] 12.50727 12.45942 12.40570 12.34833 12.28953 12.23153 12.17656 12.12683
## [225] 12.08458 12.04275 11.99474 11.94349 11.89195 11.84306 11.79976 11.76500
## [233] 11.73631 11.70933 11.68414 11.66080 11.63938 11.61996 11.60259 11.58736
## [241] 11.57434 11.56359 11.55518 11.54919 11.54986 11.55979 11.57657 11.59778
## [249] 11.62102 11.64386 11.66391 11.67874 11.68595 11.68940 11.69432 11.70038
## [257] 11.70723 11.71453 11.72195 11.72913 11.73575 11.74144 11.74589 11.74873
## [265] 11.74964 11.74415 11.73032 11.71155 11.69126 11.67286 11.65978 11.65541
## [273] 11.65637 11.65729 11.65855 11.66057 11.66374 11.66847 11.67517 11.68423
## [281] 11.69606 11.70968 11.72399 11.73923 11.75564 11.77348 11.79298 11.81438
## [289] 11.83740 11.86158 11.88699 11.91367 11.94167 11.97104 12.00183 12.03409
## [297] 12.06787 12.10321 12.14017 12.17880 12.21918 12.26129 12.30506 12.35041
## [305] 12.39725 12.44552 12.49514
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")